//
//  DeviceChartFieldModel.m
//  RuiHeApp
//
//  Created by Jun on 2022/11/24.
//

#import "DeviceChartFieldModel.h"

@implementation DeviceChartFieldModel

//初始化模型的key值
+ (NSDictionary *)modelCustomPropertyMapper {
    return @{@"keyName" : @[@"keyName",@"nickname"],
             @"unitName" : @[@"unitName",@"unit"],
             @"keyCode" : @[@"keyCode",@"nickname"]
    };
}

-(void)setI18n:(NSString *)i18n
{
    _paramLanguageDic = [i18n jsonStringToDictionary];
}

-(void)setEnumI18n:(NSString *)enumI18n
{
    _enumLanguageDic = [enumI18n jsonStringToDictionary];
}

-(NSString *)keyName
{
    //多语言
    NSString *lanKey = [NSString localLanguageMapToParamLanguage];
    if (self.paramLanguageDic[lanKey]) {
        return self.paramLanguageDic[lanKey];
    }
    return _keyName;
}

-(void)setEnums:(NSString *)enums
{
    _enumIndexs = [enums componentsSeparatedByString:@","];
}

-(void)setEnumNames:(NSString *)enumNames
{
    _enumValues = [enumNames componentsSeparatedByString:@","];
}

-(NSArray *)enumValues
{
    NSString *lanKey = [NSString localLanguageMapToParamLanguage];
    if (self.enumLanguageDic[lanKey]) {
        NSString *enumString = self.enumLanguageDic[lanKey];
        return [enumString componentsSeparatedByString:@","];
    }
    return _enumValues;
}


- (void)setContent:(NSString *)content{
    _content = content;
    //处理最高最低电压温度位置
    NSArray *array = @[@"Max Volt Position",@"Min Volt Position",@"Max Temp Position",@"Min Temp Position"];
    if (_content.length>0&&[array containsObject:_alias]) {
        NSString *num = [_content stringByReplacingOccurrencesOfString:@"," withString:@""];
        int low = [num intValue] & 0xff;
        int hight = [num intValue] >> 8 & 0xff;
        if(hight != 0){
            _content = [NSString stringWithFormat:@"%d_%d",hight,low];
        }
    }
    
//    if (_content.length>0&&[_alias isEqualToString:@"Surplus Capacity"]) {
//        //Pack 数值转换
//        _content = [_content stringByReplacingOccurrencesOfString:@"," withString:@""];
//        _content = [NSString stringWithFormat:@"%.1f",[_content integerValue]/1000.0];
//    }

}


//测试数据
+(NSArray*)getTestData:(NSArray*)keys
{
    NSMutableArray *tempArr = [NSMutableArray array];
    NSInteger timeStamp = [[NSDate date]timeIntervalSince1970];
    
    for (int i = 0; i < 30; i++) {
        NSMutableDictionary *mtbDic = [NSMutableDictionary dictionary];
        [keys enumerateObjectsUsingBlock:^(NSString  *_Nonnull key, NSUInteger idx, BOOL * _Nonnull stop) {
            int value = 10 + idx *10 + arc4random_uniform(20);
            [mtbDic setObject:[NSString stringWithFormat:@"%d",value] forKey:key];
            
        }];
        [mtbDic setObject:[NSString stringWithFormat:@"%ld",(timeStamp + i*300)*1000] forKey:@"time"];
        [tempArr addObject:mtbDic];
    }
    return tempArr.copy;
}


@end
